package com.microservices.yucloud.appweb.disruptor;

import com.alibaba.fastjson.JSON;
import com.lmax.disruptor.EventHandler;
import com.lmax.disruptor.WorkHandler;
import com.microservices.yucloud.appweb.domain.Orders;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author zy
 * @date 2019-09-05 20:15
 **/
@Slf4j
@Service
public class OrderEventConsumer implements EventHandler<OrderEvent>, WorkHandler<OrderEvent> {

    @Override
    public void onEvent(OrderEvent orderEvent, long sequence, boolean endOfBatch) throws Exception {
        log.info("消费任务开始orderEvent=[{}],sequence == [{}],[{}]", orderEvent, sequence, endOfBatch);
        onEvent(orderEvent);
    }

    @Override
    public void onEvent(OrderEvent orderEvent) throws Exception {
        Orders orders = JSON.parseObject(orderEvent.getOrder(), Orders.class);
        log.info("处理订单任务开始bizCode-[{}]:[{}]", orderEvent.getBizCode(), orders);
    }
}
